// https://leetcode.cn/problems/single-number-ii/
// Created by ade on 2022/7/27.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    // 最简单的解法
    int singleNumber1(vector<int> &nums) {
        int len = nums.size();
        if (len <= 3) return nums[0];
        sort(nums.begin(), nums.end());
        for (int i = 0; i < len - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                i = min(len - 2, i + 2);
            } else {
                return nums[i];
            }
        }
        return nums[len - 1];
    }
};

int main() {
    Solution so;
    vector<int> nums = {30000,30000,30000,500};
    int a = so.singleNumber(nums);
    cout << a << endl;
    return 0;
}